<template>
    <el-dialog title="新建" :close-on-click-modal="false" append-to-body :visible.sync="visible" lock-scroll
        width="600px">
        <el-row :gutter="15" class="">
            <el-form ref="elForm" :model="dataForm" :rules="rules" size="small" label-width="100px"
                label-position="right">
                <template v-if="!loading">
                    <el-col :span="24">
                        <el-form-item label="材料设备名称" prop="name">
                            <el-input v-model="dataForm.name" placeholder="请输入" clearable :style='{ "width": "100%" }'>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="规格型号" prop="name">
                            <el-input v-model="dataForm.name" placeholder="请输入" clearable :style='{ "width": "100%" }'>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="单价(元)" prop="name">
                            <el-input v-model="dataForm.name" placeholder="请输入" clearable :style='{ "width": "100%" }'>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="单位" prop="name">
                            <el-input v-model="dataForm.name" placeholder="请输入" clearable :style='{ "width": "100%" }'>
                            </el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="24">
                        <el-form-item label="备注" prop="name">
                            <el-input v-model="dataForm.name" placeholder="请输入" clearable :style='{ "width": "100%" }'>
                            </el-input>
                        </el-form-item>
                    </el-col>


                </template>
            </el-form>

        </el-row>
        <span slot="footer" class="dialog-footer">
            <div class="upAndDown-button" v-if="dataForm.id">

            </div>
            <el-button @click="visible = false"> 取 消</el-button>
            <el-button type="primary" @click="dataFormSubmit()" :loading="btnLoading"> 确 定</el-button>

        </span>
    </el-dialog>
</template>
<script>
import request from '@/utils/request'
import { mapGetters } from "vuex";
export default {
    components: {},
    props: [],
    data() {
        return {
            visible: false,
            loading: false,
            btnLoading: false,
            selectDialogVisible: false,
            rules:
            {
                name: [
                    {
                        required: true,
                        message: '请输入',
                        trigger: 'blur'
                    },
                ],
                sortcode: [
                    {
                        required: true,
                        message: '数字文本',
                        trigger: ["blur", "change"]
                    },
                ],
            },
        }
    },
    computed: {},
    watch: {},
    created() { },
    mounted() { },
    methods: {
        clearData() {
            this.dataForm.name = '';
            this.dataForm.sortcode = 0;
            this.dataForm.creatoruserid = "";
            this.dataForm.creatortime = "";
        },
        init(id) {
            this.dataForm.id = id || 0;
            this.visible = true;
            this.$nextTick(() => {

            });

        },
        // 表单提交
        dataFormSubmit(type) {
            this.$refs['elForm'].validate((valid) => {
                if (valid) {
                    this.request()
                }
            })
        },
        request() {
            if (!this.dataForm.id) {
                request({
                    url: '/api/example/Workpoint_class',
                    method: 'post',
                    data: _data
                }).then((res) => {
                    this.visible = false
                    this.btnLoading = false
                    this.$emit('refreshFo', true)
                }).catch(() => {
                    this.btnLoading = false
                    this.continueBtnLoading = false
                })
            } else {
                request({
                    url: '/api/example/Workpoint_class/' + this.dataForm.id,
                    method: 'PUT',
                    data: _data
                }).then((res) => {


                    this.visible = false
                    this.btnLoading = false
                    this.$emit('refreshList', true, 1)
                }).catch(() => {
                    this.btnLoading = false
                    this.continueBtnLoading = false
                })
            }
        },
    },
}

</script>
